/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "datasettemplates", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"DatasetTemplateGlobalID"}),
    @UniqueConstraint(columnNames = {"DatasetTemplateID"}),
    @UniqueConstraint(columnNames = {"DatasetTemplateName"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatasetTemplate.findAll", query = "SELECT d FROM DatasetTemplate d"),
    @NamedQuery(name = "DatasetTemplate.findByDatasetTemplateID", query = "SELECT d FROM DatasetTemplate d WHERE d.datasetTemplateID = :datasetTemplateID"),
    @NamedQuery(name = "DatasetTemplate.findByDatasetTemplateGlobalID", query = "SELECT d FROM DatasetTemplate d WHERE d.datasetTemplateGlobalID = :datasetTemplateGlobalID"),
    @NamedQuery(name = "DatasetTemplate.findByDatasetTemplateAuthor", query = "SELECT d FROM DatasetTemplate d WHERE d.datasetTemplateAuthor = :datasetTemplateAuthor"),
    @NamedQuery(name = "DatasetTemplate.findByDatasetTemplateName", query = "SELECT d FROM DatasetTemplate d WHERE d.datasetTemplateName = :datasetTemplateName"),
    @NamedQuery(name = "DatasetTemplate.findByDatesetTemplateDescription", query = "SELECT d FROM DatasetTemplate d WHERE d.datesetTemplateDescription = :datesetTemplateDescription"),
    @NamedQuery(name = "DatasetTemplate.findByDatasetTemplateCreationDate", query = "SELECT d FROM DatasetTemplate d WHERE d.datasetTemplateCreationDate = :datasetTemplateCreationDate")})
public class DatasetTemplate implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "DatasetTemplateID", nullable = false)
    private Integer datasetTemplateID;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 36)
    @Column(name = "DatasetTemplateGlobalID", nullable = false, length = 36)
    private String datasetTemplateGlobalID;
    
    @Size(max = 45)
    @Column(name = "DatasetTemplateAuthor", length = 45)
    private String datasetTemplateAuthor;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "DatasetTemplateName", nullable = false, length = 45)
    private String datasetTemplateName;
    
    @Size(max = 1024)
    @Column(name = "DatesetTemplateDescription", length = 1024)
    private String datesetTemplateDescription;
    
    @Column(name = "DatasetTemplateCreationDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date datasetTemplateCreationDate;
    
    @OneToMany(mappedBy = "metaDatasetTemplateID", fetch = FetchType.EAGER)
    private Collection<DatasetTemplateAssignment> metadataTemplateAssignmentCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "datasetTemplateID", fetch = FetchType.EAGER)
    private Collection<DatasetTemplateAssignment> datasetTemplateAssignmentCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "datasetTemplateID", fetch = FetchType.LAZY)
    private Collection<DatasetInstance> datasetInstanceCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "childDatasetTemplateID", fetch = FetchType.EAGER)
    private Collection<DatasetTemplateHierarchy> datasetTemplateHierarchyCollection;

    public DatasetTemplate() {
    }

    public DatasetTemplate(Integer datasetTemplateID) {
        this.datasetTemplateID = datasetTemplateID;
    }

    public DatasetTemplate(Integer datasetTemplateID, String datasetTemplateGlobalID, String datasetTemplateName) {
        this.datasetTemplateID = datasetTemplateID;
        this.datasetTemplateGlobalID = datasetTemplateGlobalID;
        this.datasetTemplateName = datasetTemplateName;
    }

    public Integer getDatasetTemplateID() {
        return datasetTemplateID;
    }

    public void setDatasetTemplateID(Integer datasetTemplateID) {
        this.datasetTemplateID = datasetTemplateID;
    }

    public String getDatasetTemplateGlobalID() {
        return datasetTemplateGlobalID;
    }

    public void setDatasetTemplateGlobalID(String datasetTemplateGlobalID) {
        this.datasetTemplateGlobalID = datasetTemplateGlobalID;
    }

    public String getDatasetTemplateAuthor() {
        return datasetTemplateAuthor;
    }

    public void setDatasetTemplateAuthor(String datasetTemplateAuthor) {
        this.datasetTemplateAuthor = datasetTemplateAuthor;
    }

    public String getDatasetTemplateName() {
        return datasetTemplateName;
    }

    public void setDatasetTemplateName(String datasetTemplateName) {
        this.datasetTemplateName = datasetTemplateName;
    }

    public String getDatesetTemplateDescription() {
        return datesetTemplateDescription;
    }

    public void setDatesetTemplateDescription(String datesetTemplateDescription) {
        this.datesetTemplateDescription = datesetTemplateDescription;
    }

    public Date getDatasetTemplateCreationDate() {
        return datasetTemplateCreationDate;
    }

    public void setDatasetTemplateCreationDate(Date datasetTemplateCreationDate) {
        this.datasetTemplateCreationDate = datasetTemplateCreationDate;
    }

    @XmlTransient
    public Collection<DatasetTemplateAssignment> getMetadataTemplateAssignmentCollection() {
        return metadataTemplateAssignmentCollection;
    }

    public void setMetadataTemplateAssignmentCollection(Collection<DatasetTemplateAssignment> metadataTemplateAssignmentCollection) {
        this.metadataTemplateAssignmentCollection = metadataTemplateAssignmentCollection;
    }

    @XmlTransient
    public Collection<DatasetTemplateAssignment> getDatasetTemplateAssignmentCollection() {
        return datasetTemplateAssignmentCollection;
    }

    public void setDatasetTemplateAssignmentCollection(Collection<DatasetTemplateAssignment> datasetTemplateAssignmentCollection) {
        this.datasetTemplateAssignmentCollection = datasetTemplateAssignmentCollection;
    }

    @XmlTransient
    public Collection<DatasetInstance> getDatasetInstanceCollection() {
        return datasetInstanceCollection;
    }

    public void setDatasetInstanceCollection(Collection<DatasetInstance> datasetInstanceCollection) {
        this.datasetInstanceCollection = datasetInstanceCollection;
    }

    @XmlTransient
    public Collection<DatasetTemplateHierarchy> getDatasetTemplateHierarchyCollection() {
        return datasetTemplateHierarchyCollection;
    }

    public void setDatasetTemplateHierarchyCollection(Collection<DatasetTemplateHierarchy> datasetTemplateHierarchyCollection) {
        this.datasetTemplateHierarchyCollection = datasetTemplateHierarchyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (datasetTemplateID != null ? datasetTemplateID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetTemplate)) {
            return false;
        }
        DatasetTemplate other = (DatasetTemplate) object;
        if ((this.datasetTemplateID == null && other.datasetTemplateID != null) || (this.datasetTemplateID != null && !this.datasetTemplateID.equals(other.datasetTemplateID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.DatasetTemplate[ datasetTemplateID=" + datasetTemplateID + " ]";
    }
    
}
